package cn.tedu.medicalpath.medicine.service.impl;

import cn.tedu.medicalpath.base.response.PageData;
import cn.tedu.medicalpath.medicine.mapper.MedicineMapper;
import cn.tedu.medicalpath.medicine.pojo.dto.MedicineQuery;
import cn.tedu.medicalpath.medicine.pojo.vo.MedicineVO;
import cn.tedu.medicalpath.medicine.service.MedicineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author WangPeiao
 * @date 2024/12/12\
 * @apiNote
 */
@Slf4j
@Service
public class MedicineServiceImpl implements MedicineService {
    @Autowired
    MedicineMapper medicineMapper;

    @Override
    public PageData selectMedicine(MedicineQuery medicineQuery) {
        log.debug("开始处理【查询药品信息】的业务，参数：{}",medicineQuery);
        List<MedicineVO> list = medicineMapper.selectMedicine(medicineQuery);
        //准备PageData对象用来装返回给前端的数据
        PageData medicineData = new PageData();
        //向PageData对象中装存入当前页字典数据
        medicineData.setList(list);
        //向PageData对象中装存入总记录数
        medicineData.setTotal(medicineMapper.selectMedicineCount(medicineQuery));
        //返回封装好的对象
        return medicineData;
    }

    @Override
    public List<MedicineVO> export(MedicineQuery medicineQuery) {
        log.debug("开始处理【导出表格】的业务，参数：{}",medicineQuery);
        List<MedicineVO> list = medicineMapper.selectMedicine(medicineQuery);
        if (list!=null){
            return list;
        }
        log.debug("没有查询到数据");
        return Collections.emptyList();
    }

    @Override
    public MedicineVO getMedicineById(Long id) {
        return medicineMapper.selectById(id);
    }
}
